package net.koodar.forge.system.user.service.assembler;

import net.koodar.forge.system.user.model.dto.UserParamDTO;
import net.koodar.forge.system.user.model.entity.User;
import net.koodar.forge.system.user.model.vo.UserVO;
import org.springframework.stereotype.Component;

/**
 * @author liyc
 */
@Component
public class UserAssembler {

    public UserVO convertToUserVO(User user) {
        UserVO userVo = new UserVO();
        userVo.setUserId(user.getId());
        userVo.setUsername(user.getUsername());
        userVo.setNickname(user.getNickname());
        userVo.setEmail(user.getEmail());
        userVo.setAvatar(user.getAvatar());
        userVo.setDepartmentId(user.getDepartmentId());
        return userVo;
    }

    public User convertToUser(UserParamDTO userParamDTO) {
        return convertToUser(new User(), userParamDTO);
    }

    public User convertToUser(User user, UserParamDTO userParamDTO) {
        user.setNickname(userParamDTO.getNickname());
        user.setEmail(userParamDTO.getEmail());
        user.setAvatar(userParamDTO.getAvatar());
        user.setDescription(userParamDTO.getDescription());
        user.setDepartmentId(userParamDTO.getDepartmentId());
        user.setUsername(userParamDTO.getUsername());
        return user;
    }
}
